package megrez.job.custom.web.vo;

import java.util.Date;

import org.springframework.beans.BeanUtils;

import lombok.Data;
import megrez.job.custom.component.Task;
import megrez.job.custom.domain.TaskState;

/**
 * 任务
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Data
public class TaskVO {
    private Date startUpTime;
    private Date lastRunTime;
    private int numOfRuns;
    private int numOfErrors;
    private TaskState state;
    private String message;
    private long costTime;
    private boolean scheduled;

    private String configId;
    private String className;
    private String methodName;
    private String methodParams;
    private String cronExpression;
    private String remark;
    private Boolean enabled;

    public static TaskVO of(Task task) {
        TaskVO rslt = new TaskVO();
        BeanUtils.copyProperties(task.getMonitor(), rslt);
        BeanUtils.copyProperties(task.getConfig(), rslt);
        // id 无法拷贝(泛型属性)
        if (task.getConfig() != null) {
            rslt.setConfigId(task.getConfig().getId());
        }
        return rslt;
    }
}
